package com.wwu.system.controller;

import com.wwu.common.constant.CommConst;
import com.wwu.common.web.ResultObj;
import com.wwu.common.web.ResultPage;
import com.wwu.system.entity.LoginLog;
import com.wwu.system.service.ILoginLogService;
import com.wwu.system.vo.QueryVO;
import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Arrays;

/**
 * 登陆日志监控前端控制器
 * @author 一蓑烟雨
 * @version 1.0.0
 * @date 2023-07-10 10:31
 **/
@Api(tags = "登陆监控控制器(SysLogController)")
@ApiSort(3)
@Controller
@RequestMapping("/system/log")
public class LoginLogController {
    @Resource
    private ILoginLogService loginLogService;

    /**
     * 请求转发到登陆日志主页
     * @return java.lang.String
     * @author 一蓑烟雨
     * @date 2023/7/11 10:46
     */
    @GetMapping("/loginLogMain")
    public String loginLogMainHtml() {
        return "system/log/login-log-main";
    }

    @ApiOperation(value = "分页查询登陆日志信息")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页数",paramType = "query", required = true),
            @ApiImplicitParam(name = "limit", value = "每页条数",paramType = "query", required = true),
            @ApiImplicitParam(name = "LoginLog", value = "登陆日志实体"),
            @ApiImplicitParam(name = "queryVO", value = "前端查询条件封装实体类"),
    })
    @GetMapping("/LoginLoglist")
    @ResponseBody
    public ResultPage<LoginLog> LoginLoglist(@RequestParam(defaultValue = "1") Integer page,
                                             @RequestParam(defaultValue = "5000") Integer limit,
                                             LoginLog loginLog, QueryVO queryVO){
        return loginLogService.getLoginLoglistPage(page,limit,loginLog,queryVO);
    }

    @ApiOperation(value = "删除登陆日志信息")
    @ApiOperationSupport(order = 3)
    @ApiImplicitParam(name = "recordIds", value = "日志记录id集合，以逗号分隔")
    @PutMapping("/deleteLoginLog")
    @ResponseBody
    public ResultObj deleteLoginLog(String recordIds){
        if(StringUtils.hasText(recordIds)){
            loginLogService.deleteLoginLog(Arrays.asList(recordIds.split(CommConst.SPLIT_COMMA)));
        }else{
            loginLogService.deleteLoginLog(null);
        }
        return ResultObj.success("登陆日志信息删除成功");
    }
}
